"use strict";
cc._RF.push(module, '205aeX70KNC1J3RaaQI085i', 'gameCheckLogin');
// Script/SdkTools/gameCheckLogin.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var gameShareAdsVideo_1 = require("./gameShareAdsVideo");
var PlayData_1 = require("./PlayData");
var gameCheckLogin = /** @class */ (function () {
    function gameCheckLogin() {
    }
    gameCheckLogin.getPlatformClass = function () {
        return gameShareAdsVideo_1.default.Instance.getPlatformClass();
    };
    /**
     * 游戏登录
     */
    gameCheckLogin.gameLogin = function (_force) {
        if (gameShareAdsVideo_1.default.Instance.isdebug)
            return;
        //console.log('游戏登录')
        var self = this;
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            //@ts-ignore
            wx.login({
                success: function (res) {
                    if (res.code) {
                        //发起网络请求
                        self.gameCode = res.code;
                        console.log('login 调用成功', res);
                    }
                    else {
                        console.log('登录失败！' + res.errMsg);
                    }
                }
            });
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
        }
        else {
            return false;
        }
    };
    /**
     * 获取用户信息
     */
    gameCheckLogin.wx_getUserInfo = function (callback) {
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            //获取设置
            //console.log('获取用户信息')
            //@ts-ignore
            wx.getSetting({
                success: function (res) {
                    //console.log('获取用户权限设置成功2', res.authSetting['scope.userInfo'])
                    if (res.authSetting['scope.userInfo'] == false) { //询问是否打开设置界面
                        //@ts-ignore
                        wx.showModal({
                            title: "提示！",
                            content: "用户权限未打开，请设置？",
                            success: function (res) {
                                if (res.confirm) {
                                    //console.log("confirm, continued");  //确定设置，打开设置界面
                                    //@ts-ignore
                                    wx.openSetting({
                                        success: function (res) {
                                            //console.log('设置结果',res)
                                        },
                                        fail: function () {
                                        }
                                    });
                                }
                                else if (res.cancel) {
                                    //console.log("cancel, cold");
                                }
                                else {
                                    // what happend?
                                }
                            },
                            fail: function (res) {
                                //console.log(`showModal调用失败`);
                            },
                        });
                    }
                    else { //直接请求数据 
                        //console.log('用户信息', gameConfig.userInfo)
                        if (PlayData_1.default.Instance.userInfo.name == '') {
                            //console.log('直接请求用户信息')
                            //@ts-ignore
                            wx.getUserProfile({
                                desc: '排行榜需要获取用户信息',
                                success: function (res) {
                                    console.log('获取用户信息成功', res);
                                    //window.userinfo = res.userInfo
                                    PlayData_1.default.Instance.userInfo.icon = res.userInfo.avatarUrl;
                                    PlayData_1.default.Instance.userInfo.name = res.userInfo.nickName;
                                    //console.log('获取用户信息成功', res.userInfo)
                                    callback();
                                    //Storage.setUserInfo()
                                    var info = JSON.stringify(PlayData_1.default.Instance.userInfo);
                                    cc.sys.localStorage.setItem('userinfo', info);
                                },
                                fail: function (res) {
                                    //console.log('getUserInfo 调用失败',res);
                                },
                            });
                        }
                        else {
                            callback();
                        }
                    }
                }, fail: function () {
                    //console.log('获取用户权限设置失败')
                }
            });
        }
        else {
            callback();
        }
    };
    return gameCheckLogin;
}());
exports.default = gameCheckLogin;

cc._RF.pop();